#ifndef WORKER_H
#define WORKER_H

#include <fstream>
#include "../utils/thread.h"
#include "../utils/message.h"
using namespace std;

string getCurrentDate();

class NewWorker : public Thread {
public:
	NewWorker(MessageChannel *pChannel , ofstream* pLogger , int pOutMsgType , pid_t pCommunicatorPid);
	virtual ~NewWorker();
	
	void dispatch(string pSubmissionId);
	
	bool isBusy();
	
protected:
	virtual void execute();
	bool isCommunicatorAlive();
	void recover();
	
private:
	pid_t mCommunicatorPid;
	pthread_mutex_t mWaitMutex;
	pthread_cond_t 	mWaitCond;
	string mSubmissionId;
	bool mBusy;
	ofstream* mLogger;
	MessageChannel *mChannel;
	int mOutMessageType;
	void grade();
	
	void go();

};

#endif
